Add typed Template identifier and support for v2 templates (ima-ngv2/ima-sigv2/ima-modsig/evm-sig)#5
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors IMA template handling by replacing string-based template names with a structured Template enum and adding support for several new template types, including ima-ngv2, ima-sigv2, ima-modsig, and evm-sig. The changes include new data structures for v2 digests, updated parsing logic for both ASCII and binary logs, and expanded hashing support. Feedback identifies a critical bug in the binary encoding of v2 digests that would break hash verification and recommends improving error handling in the ASCII parser by propagating hex decoding errors instead of silently defaulting to empty values.
e6ad235 to
0dcc316
Compare
0dcc316 to
8891a30
Compare
Replace the stringly-typed template name with a typed Template enum and
add full parse/encode/decode coverage for every template documented in
the IMA spec. Drops the IMA_*_TEMPLATE_NAME string constants in favor of
Template::parse / Template::as_str.
New types:
- Template — enum with variants for ima, ima-ng, ima-sig, ima-buf,
ima-modsig, ima-ngv2, ima-sigv2, evm-sig, plus Other(String) for
forward compatibility.
- DigestType (Ima / Verity / Other) and DigestV2 — model the
<digest_type>:<algo>:\0<digest> shape used by d-ngv2.
- TemplateData::{ImaModsig, ImaNgV2, ImaSigV2, EvmSig} variants and
matching ImaModsigEntry / ImaNgV2Entry / ImaSigV2Entry / EvmSigEntry
payload structs.
Parsers / encoders:
- Binary parser dispatches on Template, decoding the four new payload
shapes (decode_ima_modsig/_ngv2/_sigv2/_evm_sig) plus the d-ngv2
field decoder and u16/u32 LE field helpers.
- ASCII parser learns the same templates, including digest-type-prefixed
d-ngv2 columns and the evm-sig column layout.
- template_hash framing covers the new TemplateData variants so
recomputed template hashes still match the wire bytes.
Tests:
- Expanded src/log/parser.rs unit tests from 4 to 64 cases. New
coverage: Endianness conversion, ParseOptions builders/accessors,
decode_d_ng / decode_d_ngv2 / decode_n_ng success and error paths,
parse_u32_le / parse_u16_le, split_fields edge cases,
decode_legacy_ima error paths, per-template field-count rejection,
end-to-end roundtrips through EventLogParser for every built-in
template plus the Unknown fallback, and iterator semantics
(empty input, mid-record EOF, fused-after-error, big-endian length
decoding, max_field_len cap).
- Updated tests/integration.rs and tests/testdata.rs for the
Event::template_name → Event::template rename.
Public API: Event::template_name (String) → Event::template (Template).
Examples and README adjusted accordingly.
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
8891a30 to
a1547f9
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1547f9d14
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Motivation
template_name: Stringwith a typedTemplateidentifier to centralize recognition of built-in templates and enable parsing/decoding of newer template variants.ima-ngv2,ima-sigv2,ima-modsig,evm-sig) and typed digest namespaces (d-ngv2) so the library can round-trip and hash these templates correctly.Description
Templateenum and replaceEvent::template_name: StringwithEvent::template: Template, addingTemplate::as_str()andDisplayimpls; update docs and examples to usetemplate.as_str().DigestTypeandDigestV2types and parsing/encoding helpers (parse_prefixed_digest_v2,decode_d_ngv2,encode_d_ngv2) to supportd-ngv2style prefixed digests.TemplateDatawith variants forImaModsig,ImaNgV2,ImaSigV2, andEvmSigand implement corresponding ASCII and binary parsing/decoding functions (parse_ima_modsig,parse_ima_ngv2,parse_ima_sigv2,parse_evm_sig, anddecode_ima_modsig,decode_ima_ngv2,decode_ima_sigv2,decode_evm_sig).Template::parseand switch matching from string names to the newTemplatevariants; update template-hash framing/encoding (collect_fields,feed_event_into, legacy handling) to include the new templates andd-ngv2encoding.parse_u32_leandparse_u16_leused byevm-sigdecoding and introduceTemplateFieldIdenum for future field id usage.TemplateAPI and to expect the new template variants and behaviors.Testing
src/logand updated inline tests (parse_ascii_line, binary parser tests) which now assert againstevent.template.as_str()and new variants; those tests were updated to pass.tests/(includingascii_and_binary_agree,binary_parser_yields_multiple_events, and template-hash verification tests) after adjusting expectations to theTemplateAPI; automated tests succeeded.template.as_str(); example builds completed during the test run.